<?php
/*
	$name
	$value			gia tri thoi gian dinh dang UNIX
*/
function form_date($param)
{
	$result = '';
	if(isset($param['value']))
		$value = getdate($param['value']);
	else
		$value = getdate(time());
	$option = array();
	for($i=1; $i<=31; $i++)
		$option[$i] = $i;
	$result .= form_dropdown('_day_'.$param['name'], $option, $value['mday']);
	$option = array();
	for ($i=1; $i<=12; $i++)
		$option[$i] = $i;
	$result .= form_dropdown('_month_'.$param['name'], $option, $value['mon']);
	$option = array();
	for ($i=$value['year']-10; $i<=$value['year']+10; $i++)
		$option[$i] = $i;
	$result .= form_dropdown('_year_'.$param['name'], $option, $value['year']);
	return $result;
}

function get_form_date_value($name)
{
	$CI = &get_instance();
	$day = $CI->input->post('_day_'.$name);
	$year = $CI->input->post('_year_'.$name);
	$month = $CI->input->post('_month_'.$name);
	return mktime(0, 0, 0, $month, $day, $year);
}

function set_form_date_value($name, $default=NULL)
{
	$CI = &get_instance();
	if(($CI->input->post('_day_'.$name)) && ($CI->input->post('_year_'.$name)) && ($CI->input->post('_month_'.$name)))
	{
		$day = $CI->input->post('_day_'.$name);
		$year = $CI->input->post('_year_'.$name);
		$month = $CI->input->post('_month_'.$name);
		return mktime(0, 0, 0, $month, $day, $year);
	}
	else
		return $default;
}

function set_combo_value($name, $default=NULL)
{
	$CI = &get_instance();
	$value = $CI->input->post($name);
	if($value !== FALSE)
		return $value;
	else
		return $default;
}
?>